package com.zline.foodraise.view;

import android.content.Context;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.zline.foodraise.R;
import com.zline.foodraise.entity.NoticeBean;
import com.zline.foodraise.listener.RecyclerItemClicked;
import com.zline.foodraise.util.ImageUtil;
import com.zline.foodraise.util.TimeUtil;

import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

/**
 * Created by heshantao on 15/11/16.
 * 活动公告Item
 */
@EViewGroup(R.layout.event_notice_item)
public class EventNoticeItem extends RelativeLayout {
    private static final String LOG_TAG = EventNoticeItem.class.getSimpleName();
    RecyclerItemClicked itemClicked;
    int position;
    @Bean
    ImageUtil imageUtil;
    DisplayImageOptions options;
    ImageLoader imageLoader;
    @ViewById(R.id.event_notice_time)
    TextView time_tv;
    @ViewById(R.id.event_notice_iv)
    ImageView notice_iv;
    @ViewById(R.id.event_notice_title_tv)
    TextView title_tv;
    @ViewById(R.id.event_notice_content_tv)
    TextView content_tv;
    @Bean
    TimeUtil timeUtil;


    public EventNoticeItem(Context context) {
        super(context);
    }

    public void bind(NoticeBean bean, int position) {
        this.position = position;
        if (bean != null) {
            imageLoader = ImageLoader.getInstance();
            String picUrl = bean.getImage();
            options = imageUtil.
                    getDisplayImageOptions(R.mipmap.default_notice,
                            R.mipmap.default_notice, R.mipmap.default_notice);
            imageLoader.displayImage(picUrl, notice_iv, options);
            String title = bean.getTitle();
            title_tv.setText(title);
            String briefIntroduction = bean.getBriefIntroduction();
            content_tv.setText(briefIntroduction);
            long createTime = bean.getCreateTimeStamp();
            time_tv.setText(timeUtil.formatData3(createTime));
        }
    }

    @Click(R.id.event_notice_cv)
    void onClick(){
        itemClicked.onRecyclerItemClicked(position);
    }

    public void setRecycleItemClickListener(RecyclerItemClicked itemClickListener) {
        this.itemClicked = itemClickListener;
    }
}
